/*
 * Author  : Pallab
 * Program : J.cxx
 * 
 * Fri Jul 20 20:39:44 2012
 *
 * I have not failed, I have just found 10000 ways that won't work.
 *
 */
 
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;


#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line putchar('\n')

template<class T1>
inline void debug(T1 _x) {
    cout<<_x<<'\n';
}
template<class T1, class T2>
inline void debug(T1 _x,T2 _y) {
    cout<<_x<<' '<<_y<<'\n';
}
template<class T1, class T2, class T3>
inline void debug(T1 _x,T2 _y,T3 _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
template<class T1, class T2, class T3, class T4>
inline void debug(T1 _x,T2 _y,T3 _z,T4 _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
template< class T1>
inline void debug(T1 _array,int _size) {
    cout<<"[";
    for (int i=0; i<_size; ++i) {
        cout<<' '<<_array[i];
    }
    puts(" ]");
}

inline bool CI(int &_x) {
    return scanf("%d",&_x)==1;
}
inline bool CI(int &_x, int &_y) {
    return CI(_x)&&CI(_y) ;
}
inline bool CI(int &_x, int &_y, int &_z) {
    return CI(_x)&&CI(_y)&&CI(_z) ;
}
inline bool CI(int &_x, int &_y, int &_z, int &_zz) {
    return CI(_x)&&CI(_y)&&CI(_z)&&CI(_zz) ;
}
inline void wait( double seconds ) {
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while ( clock() < endtime ) {
        ;
    }
}
//#define debug

char muddy[51][51];
int row,col;
inline void read(){
	scanf("%d %d\n",&row,&col);
	fo(i,row){
		gets(muddy[i]);
	}
}
int hh[51][51],vv[51][51];
vector<int> e[5050];

int used[5050];
int mt[5050];

int try_kuhn(int v) {
    if (used[v])return 0;
    used[v]=1;
    foit(it,e[v]) {
        int to=(*it);
        if (mt[to]==-1||try_kuhn(mt[to])) {
            mt[to]=v;
            return 1;
        }
    }
    return 0;
}

inline void proc(){
	#ifdef debug
	fo(i,row)puts(muddy[i]);
	line;	
	#endif
	
	SET(hh,0);
	SET(vv,0);
	int h=1;
	fo(i,row){
		fo(j,col){
			if(muddy[i][j]=='*'){
				//----->
				for(int k=j;k<col&&muddy[i][k]=='*'&&!hh[i][k];++k){
					hh[i][k]=h;	
				}
				++h;
			}
		}
	}
	fo(i,row){
		fo(j,col){
			if(muddy[i][j]=='*'){
				//|
				//|
				//v
				for(int k=i;k<row&&muddy[k][j]=='*'&&!vv[k][j];++k){
					vv[k][j]=h;
				}
				++h;
			}
		}
	}
	fo(i,5050)e[i].clear();
	fo(i,row){
		fo(j,col){
			if(hh[i][j]&&vv[i][j]){
				int u = hh[i][j];
				int v = vv[i][j];
				e[u].pb(v);
				//e[v].pb(u);
			}
		}
	}
	#ifdef debug
	fo(i,row){
		fo(j,col){
			printf("%d ",hh[i][j]);
		}
		line;
	}	
	fo(i,row){
		fo(j,col){
			printf("%d ",vv[i][j]);
		}
		line;
	}
	#endif
	
	int n=h;
	SET(mt,-1);
	for(int i=1;i<n;++i){
		SET(used,0);
		try_kuhn(i);
	}
	int d=0;
	for(int i=1;i<n;++i){
		if(mt[i]!=-1){
			++d;		
		}
	}
	#ifdef debug
		cout<<n<<' '<<d<<'\n';
	#endif
	cout<<d<<'\n';
}
int main(){
	int kase;
	CI(kase);
	while(kase--){
		read();
		proc();
	}


return 0;
}
